
Page({
  /** * 页面的初始数据 */
  data: {
    heroList:[],
    loadFinish: false
  },
  // 下拉刷新
  async onPullDownRefresh(){
    await this.onShow()
    wx.stopPullDownRefresh()
  },
  async onShow(){
    await this.getHero();
    this.setData({ loadFinish: true }) 
  },

  async getHero(){
    // 获取所有英雄数据
    const { data: heroList } = await getApp().hero.orderBy('createTime', 'desc').get();
    // console.log('heroList', heroList);
    this.setData({heroList})
  },
  // 搜索事件
  async searchHandle(event){
    // 获取输入的内容
    const heroName  = event.detail
    // console.log('heroName', heroName);
    // 查询数据库
    const { data: heroList } = await getApp().hero.where({
      // 把字符串转换成正则对象查询
      name: getApp().db.RegExp({ regexp: heroName })   
    }).get()
    // console.log('heroList', heroList);
    this.setData({ heroList }) 
  },
  deleteHero(e){
    console.log(e.currentTarget.dataset);
    wx.showToast({ title: '功能升级中...', icon:'none' })
  }
})